﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WarehouseWebAPP.code.BLL
{
    public class MyEvent
    {
        private string MyMessage;
        public string message
        {
            get
            {
                return MyMessage;
            }
            set
            {
                MyMessage = value;
            }
        }
        public MyEvent(string message)
            {
                MyMessage=message;
            }
    }


    public class History
    {
        public enum ActionType {Add,Delete,Update,NewLend,NewDelivery,ReturnLend};
        static private Queue<MyEvent> HistoryStack;

        static public Queue<MyEvent> HStack
        {
            get
            {
                if (HistoryStack == null) HistoryStack = new Queue<MyEvent>();
                return HistoryStack;
            }
        }

        public static LinkedList<MyEvent> GetEvents()
        {
            
            return new LinkedList<MyEvent>(HStack);
        }
        public static void AddEvent(MyEvent anEvent)
        {
            HStack.Enqueue(anEvent);
            if (HStack.Count>5) HStack.Dequeue();
        }

        
        public static void DeleteEvents()
        {
            HStack.Clear();
        }
         
        public static MyEvent EventDecorator(ActionType action, string[] parameters, DateTime When)
        {
            string EventTime = "[ " + When.ToShortDateString() + " " + When.ToShortTimeString() + "] ";
            if (action == ActionType.Delete)
            {
                //{Serial,type}
                return new MyEvent(EventTime + parameters[1] + " " + parameters[0] + " was deleted");
            }
            if (action == ActionType.Update)
            {
                //{Serial,type}
                return new MyEvent(EventTime + parameters[1] + " " + parameters[0] + " was updated");
            }
            if (action == ActionType.Add)
            {
                //{Serial,type}
                return new MyEvent(EventTime + parameters[1] + " " + parameters[0] + " was Added");
            }
            if (action == ActionType.NewLend)
            {
                //{serial,customer,user,end_date}
                return new MyEvent(EventTime + "Item " + parameters[0] + " was leased to " + parameters[1] + " by " + parameters[2] + " till " + parameters[3]);
            }
            if (action == ActionType.NewDelivery)
            {
                //{serial,customer,user,quantity}
                return new MyEvent(EventTime + parameters[3] + " Components with Serial No. " + parameters[0] + " was delivered to " + parameters[1] + " by " + parameters[2]);
            }
                //{serial,customer}
            if (action == ActionType.ReturnLend)
            {
                return new MyEvent(EventTime + " Item " + parameters[0] + " was Returned by the customer " + parameters[1] + " to the WareHouse");
            }
            return new MyEvent("");
        }

    }
}

    

